const _form = this.getApiPage().retrievePlugin('base-forms');
const value = _form.getFormData('form_12');
const publicParams = this.getApiPage().getVariables().find(v => v.name === 'panel_type')?.value;
const event_params = this.getApiPage().getVariables().find(v => v.name === 'event_params')?.value;

this.getApiPage().setVariables([{ name: 'event_search', value: value.search }]);

console.log('publicParams', publicParams);
console.log('event_params', event_params);

async function basePost(url, params) {
  return fetch(url, {
    method: 'POST',
    headers: { "Content-type": "application/json" },
    body: JSON.stringify(params),
  }).then(res => res.json());
}

if (publicParams === '1') {
  data.occurrencePlace = event_params
} else if (publicParams === '2') {
  data.eventType = event_params
} else if (publicParams === '3') {
  data.eventGrade = event_params
} else {
  data.occurrencePlace = event_params ?? undefined
}

if (event_params) {
  const data = {
    pageNum: 1,
    pageSize: 10,
    eventTitle: value.search
  };

  basePost('/Event/event/getEventByInfo', data)
      .then(json => {
        if (json?.resultCode === '000000') {
          json.result.result.forEach(v => {
            if (publicParams?.value === '1') {
              v.groupKey = v.occurrencePlace
            } else if (publicParams?.value === '2') {
              v.groupKey = v.eventType
            } else if (publicParams?.value === '3') {
              v.groupKey = v.eventGrade
            } else {
              v.groupKey = v.occurrencePlace
            }
          })
          // panel.widgetObj.setData([json.result]);
          // panel.widgetObj.render()
        }

      })
}
